//
//  GYMineLikeProductInfoViewModel.m
//  GYDemo
//
//  Created by mac on 2018/3/26.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYMineLikeProductInfoViewModel.h"
#import "Head.h"

@implementation GYMineLikeProductInfoModel
@end

@implementation GYMineLikeProductInfoViewModel
#pragma mark - getter and setter
-(NSMutableArray *)datas
{
    if (!_datas) {
        _datas = [NSMutableArray new];
    }
    return _datas;
}
#pragma mark - method
-(void)requestDatas:(NSMutableDictionary *)para
{
    @WeakSelf;
    NSString *interface = @"buyUserCollect";
    NSString *page = para[@"page"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSArray *datalist = data[@"datalist"];
            if ([datalist isKindOfClass:[NSArray class]]) {
                NSMutableArray *arr;
                if ([page isEqualToString:@"1"]) {
                    arr = [NSMutableArray new];
                }else{
                    arr = _datas;
                }
                for (NSDictionary *dic in datalist) {
                    GYMineLikeProductInfoModel *model = [GYMineLikeProductInfoModel yy_modelWithJSON:dic];
                    [arr addObject:model];
                }
                [selfp setDatas:arr];
            }
        }
    }];
}
-(void)requestDelete:(GYMineLikeProductInfoModel *)product
{
    @WeakSelf;
    NSString *interface = @"collect";
    NSString *proid = [NSString stringWithFormat:@"%ld",product.proid];
    NSString *type = @"1";
    NSMutableDictionary *para = [NSMutableDictionary new];
    [para setObject:proid forKey:@"productid"];
    [para setObject:type forKey:@"type"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSMutableArray *arr = self.datas;
        [arr removeObject:product];
        [selfp setDatas:arr];
    }];
}
@end
